﻿using System;
using System.Windows;
using churchtool.View;
using churchtool.ViewModel;
using System.Threading;
using System.Globalization;
using churchtool.Data;

namespace churchtool
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            this.Resources.MergedDictionaries.Add(GetLanguageDictionary(new CultureInfo(GlobalSettings.GetInstance().Language)));

            // Set up the main window and its view model
            var mainWindow = new MainWindowView();
            var mainWindowViewModel = new MainWindowViewModel();
            mainWindow.DataContext = mainWindowViewModel;
            mainWindow.Show();
        }

        public static ResourceDictionary GetLanguageDictionary(CultureInfo lang)
        {
            ResourceDictionary dict = new ResourceDictionary();
            switch (lang.ToString())
            {
                case "de-DE":
                    dict.Source = new Uri("pack://application:,,,/Resources/StringResources.xaml");
                    break;
                case "en-US":
                    dict.Source = new Uri("pack://application:,,,/Resources/StringResources.en-US.xaml");
                        break;
                default:
                    dict.Source = new Uri("pack://application:,,,/Resources/StringResources.xaml");
                    break;
            }
            return dict;
        }
    }
}